package com.qky.util;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class MapUtil{
	public static Map<String,String> EntityTranMap(Object bean) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IntrospectionException {
	    Class type = bean.getClass(); 
	    Map<String,String> returnMap = new HashMap<String, String>(); 
	    BeanInfo beanInfo = Introspector.getBeanInfo(type); 
	    PropertyDescriptor[] propertyDescriptors =  beanInfo.getPropertyDescriptors(); 
	    for (int i = 0; i< propertyDescriptors.length; i++) { 
	        PropertyDescriptor descriptor = propertyDescriptors[i]; 
	        String propertyName = descriptor.getName(); 
	        if (!propertyName.equals("class")) { 
	            Method readMethod = descriptor.getReadMethod(); 
	            Object result = readMethod.invoke(bean, new Object[0]); 
	            if (result != null) { 
	                returnMap.put(propertyName, result.toString()); 
	            } 
	           /* else { 
	                returnMap.put(propertyName, ""); 
	            } */
	        } 
	    } 
	    return returnMap; 
	}
}
